//REQUIRED CLASS - KEEP THIS FILE IN THE 'project4' DIRECTORY WITH 'package project4'
//IMPLEMENT THE 'body' METHOD. MAKE AN INSTANCE OF 'Database' and return an ouput string
//DO NOT ADD METHODS

package project4;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import project1.LexicalAnalyzer;
import project1.characters;
import project2.ParseException;
import project2.Parser;

public class Project4
{
	public static void main(String[] args) {
		characters input = new characters();
		LexicalAnalyzer lexObj = new LexicalAnalyzer(input);
		
		try {
			input.SetInput(readFile("C:/Users/beebe/Documents/cs236/test/inputs/ex10.txt"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		lexObj.convert();
		Parser parsetree = new Parser(lexObj.output);
		try {
			Database db = new Database(parsetree.parseDatalogProgram());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		
	}
	
	
	
	public static String body(String[] args)
	{
		characters input = new characters();
		LexicalAnalyzer lexObj = new LexicalAnalyzer(input);
		
		try {
			input.SetInput(readFile(args[0]));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		lexObj.convert();
		Parser parsetree = new Parser(lexObj.output);
		try {
			Database db = new Database(parsetree.parseDatalogProgram());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "";
	}
	 private static String readFile( String file ) throws IOException {
		    BufferedReader reader = new BufferedReader( new FileReader (file));
		    String line  = null;
		    StringBuilder stringBuilder = new StringBuilder();
		    String ls = System.getProperty("line.separator");
		    while( ( line = reader.readLine() ) != null ) {
		        stringBuilder.append( line );
		        stringBuilder.append( ls );
		    }
		    return stringBuilder.toString();
		 }
}
